//
//  addProductListViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/26.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "ACMediaModel.h"
#import "LZPickerView.h"
#import "threelevelViewController.h"
#import "jiaotongbox.h"
#import "addvaluesTableViewCell.h"
#import "addProductListViewController.h"
#import "addpriceTableViewCell.h"
@interface addProductListViewController ()
@property(nonatomic,strong)LZPickerView *lzPickerVIew;

@end

@implementation addProductListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
      NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"LZPickerView" owner:nil options:nil];
    self.lzPickerVIew  = views[0];
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 self.view.backgroundColor = [UIColor whiteColor];

[self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
          self.navigationController.navigationBar.hidden = NO;
    if ([_type isEqualToString:@"xiugai"]) {
    self.title = NSLocalizedString(@"修改商品", nil);
}else{
    self.title = NSLocalizedString(@"添加商品", nil);
}
    _indexPathup = [NSMutableArray array];
    _indexPathdowm = [NSMutableArray array];
    
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathup addObject:dic];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[_indexPathdowm addObject:dict];
[self loaddata];
     UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"]style:UIBarButtonItemStylePlain target:self action:@selector(buttonClick)];
 self.navigationItem.leftBarButtonItem = item1;
}
- (void)buttonClick{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)loaddata{
 [MBProgressHUD showHUDAddedTo:self.view animated:YES];

NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
     if (_ipid.length==0) {
    _ipid = @"";

}
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><id>%@</id></body></message>",userName,password,website,language,BAtype,_ipid];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bgetProductList];
 [HttpTools requestWithURL:path arrays:array method:@"getProduct" success:^(id JSON) {
   [MBProgressHUD hideHUDForView:self.view animated:YES];

   NSLog(@"%@",JSON);
if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]) {
if ([[NSString stringWithFormat:@"%@",JSON[@"aouProduct"]]isEqualToString:@"update"]) {
   NSDictionary *dic = JSON[@"Product"];
   _titlename =dic[@"title"];
   _keywords = dic[@"keywords"];
   _selCategoryName = JSON[@"selCategoryName"];
   _leimuid = dic[@"categoryId"];
   _zjspecialName = JSON[@"zjspecialName"];
   _specialZJ = dic[@"specialZJ"];
   NSArray *uparray = JSON[@"ProductAttribute"];
   if (uparray != nil && ![uparray isKindOfClass:[NSNull class]] && uparray.count != 0) {
    _indexPathup = [uparray mutableCopy];
}
_descripstr = dic[@"description"];
_selGroupName = JSON[@"selGroupName"];
_productGroupId = dic[@"productGroupId"];
_selJlName = JSON[@"selJlName"];
_countUnit = dic[@"countUnit"];
_isPrice = dic[@"isPrice"];
   NSArray *downarray = JSON[@"ProductPrice"];
 if (downarray != nil && ![downarray isKindOfClass:[NSNull class]] && downarray.count != 0) {
    _indexPathdowm = [downarray mutableCopy];
}
    _totals = [NSString stringWithFormat:@"%@",dic[@"totals"]];
_sourceArea = dic[@"sourceArea"];
    _days = [NSString stringWithFormat:@"%@",dic[@"days"]];
_paymentMethod = dic[@"paymentMethod"];
_ProductImage = JSON[@"ProductImage"];
 }
    _dic = JSON;
    [self initview];
    
}else{
    [self.view makeToast:JSON[@"msg"]];
}
 } failure:^(NSError *error) {
  [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

}
- (void)initview{
if(!_tableView){
 _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 4;
            break;
        case 1:
            return self.indexPathup.count;
        case 2:
            return 4;
        case 3:
            return self.indexPathdowm.count;
        case 4:
            return 5;
        default:
            return 1;
            break;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
if (indexPath.row ==0) {
    static NSString *cellid00 = @"cellid00";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid00];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid00];
        UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 30)];
  label0.textColor = [UIColor colorWithHexString:@"0a62ea"];
    label0.text = NSLocalizedString(@"基本信息", nil);
 [cell.contentView addSubview:label0];
UIView *bomview = [[UIView alloc]initWithFrame:CGRectMake(0, 29, KScreenWidth, 1)];
bomview.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];
[cell.contentView addSubview:bomview];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品名称", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, label0.bottom,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _shangpinname = [[zhucetextfield alloc]init];
              _shangpinname.delegate = self;
    if(_titlename.length>0){
    _shangpinname.text = _titlename;
    }
 _shangpinname.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
// _shangpinname.placeholder = NSLocalizedString(@"6-20位的数字或字母", nil);
//      _shangpinname.keyboardType = UIKeyboardTypeASCIICapable;
             [cell.contentView addSubview:_shangpinname];
    }
 
        return cell;

}if (indexPath.row ==1){
  static NSString *cellid01 = @"cellid01";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid01];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid01];
         NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品关键词", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _shangpinkey = [[zhucetextfield alloc]init];
  _shangpinkey.delegate = self;
  
   if(_keywords.length>0){
    _shangpinkey.text = _keywords;
    }
 _shangpinkey.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
 [cell.contentView addSubview:_shangpinkey];
   UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, _shangpinkey.bottom,KScreenWidth-20, 30)];
    label1.numberOfLines = 0;
    label1.font = [UIFont systemFontOfSize:12];
    label1.text = NSLocalizedString(@"多个关键词用间隔符隔开；每个关键词请控制在20个字符以内；请勿添加与商品不相关的词", nil);
    label1.textColor = [UIColor colorWithHexString:@"0aa0f6"];

    [cell.contentView addSubview:label1];
    }


        return cell;

}if (indexPath.row ==2){
static NSString *cellid02 = @"cellid02";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid02];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid02];
   
   NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品类目", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _leimubutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _leimubutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
//       [_leimubutton setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];
//_leimubutton.titleEdgeInsets = UIEdgeInsetsMake(0,0, 0, 50);
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_leimubutton addSubview:image];
  if(_selCategoryName.length>0){
[_leimubutton setTitle:_selCategoryName forState:UIControlStateNormal];    }
[_leimubutton addTarget:self action:@selector(leimuaction) forControlEvents:UIControlEventTouchUpInside];
//       [_leimubutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:KScreenWidth-80];
   [cell.contentView addSubview:_leimubutton];
 UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, _leimubutton.bottom,KScreenWidth-20, 30)];
    label1.numberOfLines = 0;
    label1.font = [UIFont systemFontOfSize:12];
    label1.text = NSLocalizedString(@"类目越精确，越有利于买家定位，尽量不要选择含“其它”的类目", nil);
    label1.textColor = [UIColor colorWithHexString:@"0aa0f6"];
    [cell.contentView addSubview:label1]; }
 
return cell;
}else{
static NSString *cellid03 = @"cellid03";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid03];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid03];
     NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-浙江优品", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
//label.attributedText = attrStr;
label.text = string;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 _zjyoupinbutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _zjyoupinbutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
      [_zjyoupinbutton addTarget:self action:@selector(zjyoupaction) forControlEvents:UIControlEventTouchUpInside];

//       [_zjyoupinbutton setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_zjyoupinbutton addSubview:image];
 if(_zjspecialName.length>0){
[_zjyoupinbutton setTitle:_zjspecialName forState:UIControlStateNormal];    }
//       [_zjyoupinbutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:(KScreenWidth-60)];
   [cell.contentView addSubview:_zjyoupinbutton];
 UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, _zjyoupinbutton.bottom,KScreenWidth-20, 30)];
    label1.numberOfLines = 0;
    label1.font = [UIFont systemFontOfSize:12];
    label1.text = NSLocalizedString(@"选择浙江优品类目可在浙江优品分类中推出，可不选", nil);
    label1.textColor = [UIColor colorWithHexString:@"0aa0f6"];
    [cell.contentView addSubview:label1]; }
   
return cell;
}

}
else if (indexPath.section ==1) {

static NSString *cellid10 = @"cellid10";
    addvaluesTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid10];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[addvaluesTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid10];
    }
    cell.dic = _indexPathup[indexPath.row];
        return cell;

}else if (indexPath.section ==2) {
if (indexPath.row==0) {
    static NSString *cellid20 = @"cellid20";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid20];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid20];
    
   UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 30)];
    label0.numberOfLines = 0;
    label0.font = [UIFont systemFontOfSize:12];
    label0.text = NSLocalizedString(@"商品属性越完整,属性名和属性值越准确，目标客户越容易搜索到", nil);
    label0.textColor = [UIColor colorWithHexString:@"0aa0f6"];
    [cell.contentView addSubview:label0];
     NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品图片", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 30,100, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(label.right, 30,KScreenWidth-20-100, 20)];
  label2.textColor = [UIColor colorWithHexString:@"0aa0f6"];
label2.text = NSLocalizedString(@"(单个图片最大5M，最多上传5张图片)", nil);
    label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
// _shangpinview = [[photoview alloc]initWithFrame:CGRectMake(10, 50, KScreenWidth-20, (kScreenWidth-16 - 2 * 3) / 4+10)];
//    _shangpinview.maxCount = 5;
//    if (_ProductImage != nil && ![_ProductImage isKindOfClass:[NSNull class]] && _ProductImage.count != 0) {
//      _shangpinview.image =   [_ProductImage mutableCopy];
//
//}
//    [cell.contentView addSubview:_shangpinview];
//    [_shangpinview initCollectionView];
 _mediaView = [[ACSelectMediaView alloc] initWithFrame:CGRectMake(10, 50, KScreenWidth-20, (kScreenWidth-16 - 2 * 3) / 4+10)];
    _mediaView.showDelete = YES;
    _mediaView.showAddButton = YES;
   _mediaView.maxImageSelected = 5;
     if (_ProductImage != nil && ![_ProductImage isKindOfClass:[NSNull class]] && _ProductImage.count != 0) {
     
      _shangpinview.image =   [_ProductImage mutableCopy];
NSMutableArray *array = [NSMutableArray array];
for (NSDictionary *dic in _ProductImage) {
    [array addObject:dic[@"fileurl"]];
    
}
_mediaView.preShowMedias  = array;
}
// _mediaView.preShowMedias = @[  @"http://c.hiphotos.baidu.com/image/h%3D200/sign=ad1c53cd0355b31983f9857573ab8286/279759ee3d6d55fbb02469ea64224f4a21a4dd1f.jpg", @"http://img15.3lian.com/2015/h1/280/d/5.jpg"];
    _mediaView.allowMultipleSelection = NO;
    [cell.contentView addSubview:_mediaView];
[_mediaView observeSelectedMediaArray:^(NSArray<ACMediaModel *> *list) {
    _selimage = list;
    }];
   [_mediaView observeViewHeight:^(CGFloat mediaHeight) {
     [_tableView reloadData];
    }];

}
//    cell.backgroundColor = [UIColor yellowColor];
 
    
        return cell;
}
else if (indexPath.row==1) {
    static NSString *cellid21 = @"cellid21";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid21];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid21];
    NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品描述", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
                 _miaoshuTextView = [[UITextView alloc]init];
      _miaoshuTextView.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 80);
      if(_descripstr.length>0){
_miaoshuTextView.text = _descripstr  ;

      }
      _miaoshuTextView.delegate = self;
    _miaoshuTextView.layer.cornerRadius=8.0f;
   _miaoshuTextView.layer.masksToBounds=YES;
    _miaoshuTextView.layer.borderColor=[[UIColor grayColor]CGColor];
    _miaoshuTextView.layer.borderWidth= 1.0f;
             [cell.contentView addSubview:_miaoshuTextView];  }
    
    return cell;
    
    }
    
    else if (indexPath.row==2) {
    static NSString *cellid22 = @"cellid22";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid22];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid22];
    
    NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-选择分组", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    
    NSArray *array = _dic[@"pdgrouplist"];
    if (array.count!=0) {
     _fenzubutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _fenzubutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
       if(_selGroupName.length>0){
[_fenzubutton setTitle:_selGroupName forState:UIControlStateNormal];    }
      [_fenzubutton addTarget:self action:@selector(fenzuaction) forControlEvents:UIControlEventTouchUpInside];

UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_fenzubutton addSubview:image];

   [cell.contentView addSubview:_fenzubutton];
}else{

_fenzufield = [[zhucetextfield alloc]init];
     _fenzufield.delegate = self;
 _fenzufield.frame = CGRectMake(10, label.bottom, (KScreenWidth-90), 40);
             [cell.contentView addSubview:_fenzufield];
}

  
}
    return cell;
    
    } else  {
    static NSString *cellid23 = @"cellid23";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid23];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid23];
       UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 30)];
  label0.textColor = [UIColor colorWithHexString:@"0a62ea"];
    label0.text = NSLocalizedString(@"添加商品-交易信息", nil);
 [cell.contentView addSubview:label0];
UIView *bomview = [[UIView alloc]initWithFrame:CGRectMake(0, 29, KScreenWidth, 1)];
bomview.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];
[cell.contentView addSubview:bomview];
  NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-计量单位", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 30,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
     _danweibutton = [zhucebutton buttonWithType:UIButtonTypeCustom];
      _danweibutton.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
          if(_selJlName.length>0){
[_danweibutton setTitle:_selJlName forState:UIControlStateNormal];    }
      [_danweibutton addTarget:self action:@selector(danweiaction) forControlEvents:UIControlEventTouchUpInside];
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth-50,10 , 20, 20)];
image.image = [UIImage imageNamed:@"下拉"];
[_danweibutton addSubview:image];
//       [_danweibutton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight
//                                    imageTitleSpace:(KScreenWidth-60)];
   [cell.contentView addSubview:_danweibutton]; }

     
    return cell;
    
    }

}
else if (indexPath.section ==3) {

static NSString *cellid30 = @"cellid30";
    addpriceTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid30];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[addpriceTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid30];
    }
    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}
else {

if (indexPath.row ==0) {
    static NSString *cellid40 = @"cellid40";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid40];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid40];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-供货总量", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _gonghuo = [[zhucetextfield alloc]init];
     _gonghuo.delegate = self;
 _gonghuo.frame = CGRectMake(10, label.bottom, (KScreenWidth-90), 40);
           if(_totals.length>0){
_gonghuo.text = _totals;
}             [cell.contentView addSubview:_gonghuo];
              UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(_gonghuo.right, _gonghuo.top,KScreenWidth-80, 40)];
  label1.textColor = [UIColor colorWithHexString:@"484848"];
label1.text = NSLocalizedString(@"添加商品-件/月", nil);
    label1.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label1];
}
return cell;
}else if (indexPath.row ==1) {
    static NSString *cellid41 = @"cellid41";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid41];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid41];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-源产地", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _chandi = [[zhucetextfield alloc]init];
     _chandi.delegate = self;
               if(_sourceArea.length>0){
_chandi.text = _sourceArea;
}
 _chandi.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_chandi];
               UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, _chandi.bottom,KScreenWidth-20, 30)];
    label1.numberOfLines = 0;
    label1.font = [UIFont systemFontOfSize:12];
    label1.text = NSLocalizedString(@"请填写商品的源产地，如：浙江省/杭州市", nil);
    label1.textColor = [UIColor colorWithHexString:@"0aa0f6"];

    [cell.contentView addSubview:label1];
}
return cell;
}else if (indexPath.row ==2) {
    static NSString *cellid42 = @"cellid42";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid42];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid42];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-发货期", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label0 = [[UILabel alloc]initWithFrame:CGRectMake(10, label.bottom,150, 40)];
    label0.font = [UIFont systemFontOfSize:14];
    label0.text = NSLocalizedString(@"自买家付款之日起", nil);
    label0.textColor = [UIColor colorWithHexString:@"484848"];
    [cell.contentView addSubview:label0];
      _daysfield = [[zhucetextfield alloc]init];
     _daysfield.delegate = self;
               if(_days.length>0){
_daysfield.text = _days;
}
           _daysfield.keyboardType = UIKeyboardTypeNumberPad;
 _daysfield.frame = CGRectMake(label0.right, label.bottom, 50, 40);
             [cell.contentView addSubview:_daysfield];
               UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(_daysfield.right, label.bottom,80, 40)];
    label1.font = [UIFont systemFontOfSize:14];
    label1.text = NSLocalizedString(@"天内发货", nil);
    label1.textColor = [UIColor colorWithHexString:@"484848"];
    [cell.contentView addSubview:label1];
}
return cell;
}else if (indexPath.row ==3) {
    static NSString *cellid43 = @"cellid43";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid43];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid43];
 NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-付款方式", nil)];
  
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
label.text = string;
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _paytype = [[zhucetextfield alloc]init];
     _paytype.delegate = self;
                   if(_paymentMethod.length>0){
_paytype.text = _paymentMethod;
}
 _paytype.frame = CGRectMake(10, label.bottom, (KScreenWidth-20), 40);
             [cell.contentView addSubview:_paytype];
               UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, _paytype.bottom,KScreenWidth-20, 30)];
    label1.numberOfLines = 0;
    label1.font = [UIFont systemFontOfSize:12];
    label1.text = NSLocalizedString(@"请填写支持的付款方式及交货付款比例等", nil);
    label1.textColor = [UIColor colorWithHexString:@"0aa0f6"];

    [cell.contentView addSubview:label1];
}
return cell;
}
else{
     static NSString *CellIdentifier2 = @"Cellbendititlepic2";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
        cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    }
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
      button.frame = CGRectMake(20, 10, KScreenWidth-40, 40);
button.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button setTitle:NSLocalizedString(@"保存", nil) forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button.layer.cornerRadius = button.height/2;
        [button addTarget:self action:@selector(baocunaction) forControlEvents:UIControlEventTouchUpInside];
    
[cell.contentView addSubview:button];
    return cell;
    
  
    }
}

}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
 if (section==1) {
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,KScreenWidth-20, 20)];
  label.textColor = [UIColor colorWithHexString:@"484848"];
  NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-商品属性", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
      [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
label.attributedText = attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:label];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(KScreenWidth-120, 5, 80, 20);
    button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
button.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[button setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
[button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
[button setTitle:NSLocalizedString(@"添加商品-添加属性", nil) forState:UIControlStateNormal];
    button.layer.masksToBounds=YES;
                   button.layer.cornerRadius=2.0f;
   [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[button addTarget:self action:@selector(addaction:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:button];
     
return bgView;
 }
 else if (section==3) {
 UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,40, 20)];
   NSString *string =[NSString stringWithFormat:@"%@",NSLocalizedString(@"添加商品-价格", nil)];
   NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:string];
  [attrStr addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor]
                range:NSMakeRange(0, 1)];
 label.textColor = [UIColor colorWithHexString:@"484848"];
label.attributedText =attrStr;
    label.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:label];
       _fanweibox = [fanweibox checkBoxFootView];

    [_fanweibox setSelectRowBlock:^(NSString *rowTitle) {
    _isPrice = rowTitle;

}];
    if ([_fanweibox.orderString isEqualToString:@"1"]) {
    _isPrice = @"1";
}

if ([_isPrice isEqualToString:@"1"]) {
        _fanweibox.seltag = 1;

}else{
    _fanweibox.seltag = 0;

}
 _fanweibox.frame = CGRectMake(label.right, 5,KScreenWidth-20-50-100, 20);
             [bgView addSubview:_fanweibox];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(KScreenWidth-110, 5, 100, 20);
    button.titleLabel.font = [UIFont systemFontOfSize: 14.0];
button.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[button setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
[button layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft
                                    imageTitleSpace:0];
[button setTitle:NSLocalizedString(@"添加商品-增加价格区间", nil) forState:UIControlStateNormal];
    button.layer.masksToBounds=YES;
                   button.layer.cornerRadius=2.0f;
   [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
[button addTarget:self action:@selector(addpriceaction:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:button];
     
return bgView;
 }
 else{
 return nil;
 }
}
- (void)addaction:(UIButton *)btn{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathup addObject:dic];
//[_tableView reloadData];
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1]; //你需要更新的组数
[_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];  //collection 相同
}
- (void)addpriceaction:(UIButton *)btn{

if ([_fanweibox.orderString isEqualToString:@"1"]){
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[_indexPathdowm addObject:dic];
//[_tableView reloadData];
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:3]; //你需要更新的组数
[_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
} //collection 相同
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return 30;
    } else
    if (section==3) {
        return 30;
    }
    return 0;
}
- (void)zjyoupaction{

NSArray *array = _dic[@"zjSpecialList"];
NSMutableArray *muaarray = [NSMutableArray array];
for (NSDictionary *dic in array) {
    [muaarray addObject:dic[@"dictname"]];
}
[self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
self.lzPickerVIew.dataSource =muaarray;
    [self.lzPickerVIew show];
         __weak typeof(self) weakSelf = self;

 self.lzPickerVIew.selectValue  = ^(NSString *value){

        [weakSelf.zjyoupinbutton setTitle:value forState:UIControlStateNormal];
      _zjspecialName = value;
     for (NSDictionary *dic in array) {
   
   if ([value isEqualToString:dic[@"dictname"]]) {
   _specialZJ = dic[@"id"];
}
}
    };

}
- (void)fenzuaction{
NSArray *array = _dic[@"pdgrouplist"];
NSMutableArray *muaarray = [NSMutableArray array];
for (NSDictionary *dic in array) {
    [muaarray addObject:dic[@"name"]];
}
[self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
self.lzPickerVIew.dataSource =muaarray;
 [self.lzPickerVIew show];
         __weak typeof(self) weakSelf = self;

 self.lzPickerVIew.selectValue  = ^(NSString *value){

        [weakSelf.fenzubutton setTitle:value forState:UIControlStateNormal];
      _selGroupName = value;
     for (NSDictionary *dic in array) {
   
   if ([value isEqualToString:dic[@"name"]]) {
   _productGroupId = dic[@"id"];
}
}
    };
}
- (void)danweiaction{
NSArray *array = _dic[@"jldictlist"];
NSMutableArray *muaarray = [NSMutableArray array];
for (NSDictionary *dic in array) {
    [muaarray addObject:dic[@"dictname"]];
}
[self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
self.lzPickerVIew.dataSource =muaarray;
 [self.lzPickerVIew show];
         __weak typeof(self) weakSelf = self;

 self.lzPickerVIew.selectValue  = ^(NSString *value){

        [weakSelf.danweibutton setTitle:value forState:UIControlStateNormal];
      _selJlName = value;
     for (NSDictionary *dic in array) {
   
   if ([value isEqualToString:dic[@"name"]]) {
   _countUnit = dic[@"id"];
}
}
    };
}
- (void)leimuaction{
threelevelViewController *vc = [[threelevelViewController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
vc.type = @"shangpin";
[vc setSelectRowBlock:^(NSString *rowTitle, NSString *ipid) {
[_leimubutton setTitle:rowTitle forState:UIControlStateNormal];
_selCategoryName = rowTitle;
_leimuid = ipid;
[_tableView reloadData];
}];
[self.navigationController pushViewController:vc animated:YES];

}
- (void)baocunaction{

   _titlename = [_shangpinname.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _keywords= [_shangpinkey.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _descripstr= [_miaoshuTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _totals= [_gonghuo.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _sourceArea= [_chandi.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _days= [_daysfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   _paymentMethod= [_paytype.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
      NSString *newfenzu= [_fenzufield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSDictionary*dic = _indexPathup[0];
  NSString *name =[NSString stringWithFormat:@"%@",dic[@"name"]];
    
NSString *values =[NSString stringWithFormat:@"%@",dic[@"values"]];
 name =    [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 values =   [values stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
  NSString *startNum = [NSString string];
  NSString *endNum = [NSString string];
  NSString *price = [NSString string];
if ([_fanweibox.orderString isEqualToString:@"1"]){
     NSDictionary*dict = _indexPathdowm[0];
    startNum =[NSString stringWithFormat:@"%@",dict[@"startNum"]];
    
endNum =[NSString stringWithFormat:@"%@",dict[@"endNum"]];
price =[NSString stringWithFormat:@"%@",dict[@"price"]];
 startNum =    [startNum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 endNum =   [endNum stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
   price =  [price stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 }
  if ([_titlename isEqualToString:@""]|| _titlename.length == 0){
     [self.view makeToast:NSLocalizedString(@"添加商品-商品名称为空", nil)];
}
else if ([_keywords isEqualToString:@""]|| _keywords.length == 0){
     [self.view makeToast:NSLocalizedString(@"添加商品-商品关键字为空", nil)];
}else if ([_descripstr isEqualToString:@""]|| _descripstr.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-商品描述为空", nil)];
}else if ([_totals isEqualToString:@""]|| _totals.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-供货总量为空", nil)];
}else if ([_sourceArea isEqualToString:@""]|| _sourceArea.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-源产地为空", nil)];
}else if ([_days isEqualToString:@""]|| _days.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-发货期为空", nil)];
}else if ([_titlename isEqualToString:@""]|| _titlename.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-用户名为空", nil)];
}else if ([_selCategoryName isEqualToString:@""]|| _selCategoryName.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-商品类目为空", nil)];
}else if (_selimage.count == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-商品照片为空", nil)];
}else if ([_selGroupName isEqualToString:@""]|| _selGroupName.length == 0){
if([newfenzu isEqualToString:@""]|| newfenzu.length == 0)
{
     [self.view makeToast:NSLocalizedString(@"注册信息-商品分组为空", nil)];

}
}else if ([_selJlName isEqualToString:@""]|| _selJlName.length == 0){
     [self.view makeToast:NSLocalizedString(@"注册信息-计量单位为空", nil)];
}
else if ([_fanweibox.orderString isEqualToString:@"1"]&&(startNum.length ==0 ||endNum.length ==0 ||price.length ==0||[startNum isEqualToString:@"(null)"]||[endNum isEqualToString:@"(null)"]||[price isEqualToString:@"(null)"])){

    

    [self.view makeToast:NSLocalizedString(@"注册信息-自定义价格区间为空", nil)];



}


else if(name.length ==0 ||values.length ==0 ||[name isEqualToString:@"(null)"]||[values isEqualToString:@"(null)"])
{
    

    [self.view makeToast:NSLocalizedString(@"注册信息-商品属性为空", nil)];



}
else
{

NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];

NSString *imageStrurl = [NSString string];//选择的网络图片
NSString *imageStrdata = [NSString string];//选择的本地图片

NSMutableArray *imageStrurlarray = [NSMutableArray array];
NSMutableArray *imagenamearray = [NSMutableArray array];
NSMutableArray *imagedataarray = [NSMutableArray array];

 for (ACMediaModel *model in _selimage) {
 
 if(model.imageUrlString.length>0){
 for (NSDictionary *dic in _ProductImage ) {
    if ([dic[@"fileurl"]isEqualToString:model.imageUrlString]) {
    [imageStrurlarray addObject:dic[@"id"]];
}
}

 }else{

    UIImage *image  = model.image;
      NSData *data = UIImageJPEGRepresentation(image, 1.0);
            if (data.length>100*1024)
            {
                if (data.length>1024*1024) {//1M以及以上
                    data = UIImageJPEGRepresentation(image, 0.1);
                }else if (data.length>512*1024) {//0.5M-1M
                    data = UIImageJPEGRepresentation(image, 0.5);
                }else if (data.length>200*1024) {//0.25M-0.5M
                    data = UIImageJPEGRepresentation(image, 0.9);
                }
            }

             NSString *imageStr = [DES3Util encrypt:data] ;
                 [imagenamearray addObject:model.name];
                 [imagedataarray addObject:imageStr];
}
}
 if (imageStrurlarray.count>0) {
    imageStrurl = [imageStrurlarray componentsJoinedByString:@","];
imageStrurl = [NSString stringWithFormat:@"<delPdimgId>%@</delPdimgId>",imageStrurl];
}else{
    imageStrurl =@"";
}
if (imagedataarray.count>0) {
for (int i = 0; i<imagenamearray.count; i++) {
    NSString*   name = [NSString stringWithFormat:@"<filename>%@</filename>",imagenamearray[i]];
    NSString*  data = [NSString stringWithFormat:@"<fileContent>%@</fileContent>",imagedataarray[i]];
   NSString *namestring = [NSString stringWithFormat:@"<ProductImage>%@%@</ProductImage>",name,data];
imageStrdata = [imageStrdata stringByAppendingString:namestring];
}
 imageStrdata = [NSString stringWithFormat:@"<ProductImages>%@</ProductImages>",imageStrdata];


}else{
   imageStrdata = @"";

}
NSString *pricestr = [NSString string];
if ([_isPrice isEqualToString:@"0"]) {
    pricestr = @"0";
}else{
for (int i = 0; i<_indexPathdowm.count; i++) {
    NSString*   startNum = [NSString stringWithFormat:@"<startNum>%@</startNum>",_indexPathdowm[i][@"startNum"]];
    NSString*   endNum = [NSString stringWithFormat:@"<endNum>%@</endNum>",_indexPathdowm[i][@"endNum"]];
        NSString*   price = [NSString stringWithFormat:@"<price>%@</price>",_indexPathdowm[i][@"price"]];

   NSString *namestring = [NSString stringWithFormat:@"<ProductPrice>%@%@%@</ProductPrice>",startNum,endNum,price];
pricestr = [pricestr stringByAppendingString:namestring];
}
 pricestr = [NSString stringWithFormat:@"<ProductPrices>%@</ProductPrices>",pricestr];

}
NSString *Productstr = [NSString string];
for (int i = 0; i<_indexPathup.count; i++) {

 NSString*   name = [NSString stringWithFormat:@"<name>%@</name>",_indexPathup[i][@"name"]];
    NSString*   values = [NSString stringWithFormat:@"<values>%@</values>",_indexPathup[i][@"values"]];
   NSString *Productstring = [NSString stringWithFormat:@"<ProductAttribute>%@%@</ProductAttribute>",name,values];
Productstr = [Productstr stringByAppendingString:Productstring];


}
 Productstr = [NSString stringWithFormat:@"<ProductAttributes>%@</ProductAttributes>",Productstr];


   if(_specialZJ.length>0){
   }else{
      _specialZJ = @"";

   }
   if(_paymentMethod.length>0){
   }else{
      _paymentMethod = @"";

   }
    if (_ipid.length==0) {
    _ipid = @"";

}
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><Product><id>%@</id><title>%@</title><keywords>%@</keywords><categoryId>%@</categoryId><specialZJ>%@</specialZJ><description>%@</description>                                                                                                                                                     <productGroupId>%@</productGroupId><countUnit>%@</countUnit><isPrice>%@</isPrice><totals>%@</totals><sourceArea>%@</sourceArea><days>%@</days><paymentMethod>%@</paymentMethod></Product>%@%@%@%@</body></message>",userName,password,website,language,BAtype,_ipid,_titlename,_keywords,_leimuid,_specialZJ,_descripstr,_productGroupId,_countUnit,_isPrice,_totals,_sourceArea,_days,_paymentMethod,Productstr,pricestr,imageStrdata,imageStrurl];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bgetProductList];
 [HttpTools requestWithURL:path arrays:array method:@"modifyProduct" success:^(id JSON) {
    NSLog(@"%@",JSON);
//     MBProgressHUD * hud =  [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//                hud.labelText = JSON[@"msg"];

         [self.view makeToast:JSON[@"msg"]];

//                        [NSThread sleepForTimeInterval:1.0];
[self performSelector: @selector(popaction) withObject: nil afterDelay:1.0f];

if([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"]){

//[self.navigationController popViewControllerAnimated:YES];
}

 } failure:^(NSError *error) {
  [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];


}
}
- (void)popaction{
//    [defaults removeObjectForKey:@"dic"];

[self.navigationController popViewControllerAnimated:YES];

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{if(indexPath.section==0){
if(indexPath.row ==0)
{
return 90;
}else if (indexPath.row==1){
return 90;
}else{
return 100;
}

}else if (indexPath.section==1) {
    return 50;
 
}else if (indexPath.section==2) {
 if(indexPath.row ==0)
{
return _mediaView.height+50;
}else if(indexPath.row ==1)
{
return 100;
}else if(indexPath.row ==2)
{
return 60;
}else if(indexPath.row ==3)
{
return 90;
}

else{

return 100;
}
 
}

else if (indexPath.section==3) {
    return 50;
 
}else if (indexPath.section==4) {
  if(indexPath.row ==0)
{
return 60;
}else  if(indexPath.row ==1)
{
return 60+20;
}else  if(indexPath.row ==2)
{
return 60;
}else
{
return 60+20+10;
}
 
 
}
else
{
return 60;
}


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
